# Author    : CoffeeChicken
# Date      : 2020-10-11 23:36
# Function  : 演示 下载种子


import requests
from lxml import etree
import os
import time

url_front = "http://www.ac41.xyz/index.php?page="
headers = {
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
                  "Chrome/85.0.4183.121 Safari/537.36"
}

all_img_links = []
add_link = "http://www.ac41.xyz/"

for i in range(1):
    path = ""
    url = url_front + str(i + 1)
    response_front = requests.get(url, headers).text
    tree = etree.HTML(response_front)
    link_list = tree.xpath("//ul[@class='list']/li/a/@href")

    all_pages_img_links = []
    for links in link_list:
        response_page = requests.get(links, headers).text
        # print(response_page)
        tree1 = etree.HTML(response_page)
        torrent_links = tree1.xpath("//div[@class='download']/p[1]/a/@href")
        all_pages_img_links += torrent_links
    # if not os.path.exists(path):
    #     os.mkdir(path)
    # for index in range(len(all_pages_img_links)):
    #     response_pic = requests.get(all_pages_img_links[index], headers)
    #     with open(path + "/" + str(int(index + 1)) + ".jpg", "wb") as fp:
    #         fp.write(response_pic.content)
    #     print("======>", path, index, "<=====", "is ok")
    #     time.sleep(2)
